package com.lifeservice.console.service.impl;

import com.lifeservice.common.utils.DateUtils;
import com.lifeservice.common.utils.SnowFlakeUtil;
import com.lifeservice.console.domain.LifeWxappConfig;
import com.lifeservice.console.mapper.LifeWxappConfigMapper;
import com.lifeservice.console.service.ILifeWxappConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 微信配置Service业务层处理
 *
 * @author lifeservice
 * @date 2023-02-27
 */
@Service
public class LifeWxappConfigServiceImpl implements ILifeWxappConfigService {
    @Autowired
    private LifeWxappConfigMapper lifeWxappConfigMapper;

    /**
     * 查询微信配置
     *
     * @param id 微信配置主键
     * @return 微信配置
     */
    @Override
    public LifeWxappConfig selectLifeWxappConfigById(String id) {
        return lifeWxappConfigMapper.selectLifeWxappConfigById(id);
    }

    /**
     * 查询微信配置列表
     *
     * @param lifeWxappConfig 微信配置
     * @return 微信配置
     */
    @Override
    public List<LifeWxappConfig> selectLifeWxappConfigList(LifeWxappConfig lifeWxappConfig) {
        return lifeWxappConfigMapper.selectLifeWxappConfigList(lifeWxappConfig);
    }

    /**
     * 新增微信配置
     *
     * @param lifeWxappConfig 微信配置
     * @return 结果
     */
    @Override
    public int insertLifeWxappConfig(LifeWxappConfig lifeWxappConfig) {
        lifeWxappConfig.setId(SnowFlakeUtil.getInstance().nextId());
        lifeWxappConfig.setCreateTime(DateUtils.getNowDate());
        return lifeWxappConfigMapper.insertLifeWxappConfig(lifeWxappConfig);
    }

    /**
     * 修改微信配置
     *
     * @param lifeWxappConfig 微信配置
     * @return 结果
     */
    @Override
    public int updateLifeWxappConfig(LifeWxappConfig lifeWxappConfig) {
        lifeWxappConfig.setUpdateTime(DateUtils.getNowDate());
        return lifeWxappConfigMapper.updateLifeWxappConfig(lifeWxappConfig);
    }

    /**
     * 批量删除微信配置
     *
     * @param ids 需要删除的微信配置主键
     * @return 结果
     */
    @Override
    public int deleteLifeWxappConfigByIds(String[] ids) {
        return lifeWxappConfigMapper.deleteLifeWxappConfigByIds(ids);
    }

    /**
     * 删除微信配置信息
     *
     * @param id 微信配置主键
     * @return 结果
     */
    @Override
    public int deleteLifeWxappConfigById(String id) {
        return lifeWxappConfigMapper.deleteLifeWxappConfigById(id);
    }

    /**
     * 查询开启的小程序配置信息
     *
     * @return
     */
    @Override
    public LifeWxappConfig selectWxappConfig() {
        return lifeWxappConfigMapper.selectWxappConfig();
    }
}
